﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WcfRoutingSample.Contracts;
using EnCor.Wcf;

namespace WcfRoutingSampe.Client
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            string address = System.Configuration.ConfigurationSettings.AppSettings["ServiceUrl"];
            if (string.IsNullOrEmpty(address))
            {
                MessageBox.Show("Please configure the address of remote service first");
                return;
            }
            IEchoService client = ClientFactory.CreateClient<IEchoService>(address);
            using ((IDisposable)client)
            {
                try
                {
                    string result = client.Echo(txtInput.Text);
                    txtOutput.Text = result + "\r\n" + txtOutput.Text;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
    }
}
